<?php

namespace app\api\controller;

use app\api\model\wanlshop\Shop as ShopModel;
use app\api\model\ShopCategory as ShopCategoryModel;
use app\common\controller\Api;
use think\Db;


/**
 * 认证机构列表
 */
class Shop extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        $this->model = new ShopModel();
    }

    //项目列表
    public function lists()
    {
        $list = $this->model
//            ->where(['pid'=>$pid,'type'=>'goods'])
//            ->field('id,name,image')
            ->select();

        $this->success('ok',$list);
    }

    //参与项目的机构列表
    public function listsbyprojectId()
    {

        $project_id = $this->request->param('project_id');

        if(!$project_id){
            $this->error('参数错误');
        }

        $shopIds = ShopCategoryModel::where('source_id')->column('shop_id');

        $list = $this->model
            ->where(['id','in',$shopIds])
//            ->field('id,name,image')
            ->select();

        $this->success('ok',$list);
    }

    //机构详情
    public function detail()
    {
        $id = $this->request->param('id');

        if(!$id){
            $this->error('参数错误');
        }

        $info = $this->model->where(['id'=>$id])
//            ->field('id,name,image,range')
            ->find();

        $this->success('ok',$info);
    }


}
